// import post from '@dfeidao/atom-web/msg/post';
import set from '@dfeidao/atom-web/global/set';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';

import error from '@dfeidao/atom-web/msgbox/error';
// import success from '@dfeidao/atom-web/msgbox/success';
import set_user from '@dfeidao/atom-web/storage/put';


import direct_to from '@dfeidao/atom-web/url/direct-to';
import { post } from '@dfeidao/send-msg/browser/request';
import { login } from '../../atom/config';
export default async function a001(fd: IFeidaoAiBrowserComponent) {
	// todo 点击“登录”操作
	const user_name = fd.data.node.querySelector('[data-id="user_name"]') as HTMLInputElement;
	const user_pwd = fd.data.node.querySelector<HTMLInputElement>('[data-id="user_pwd"]');
	if (!user_name.value || !user_pwd.value) {
		error('请输入用户名或密码');
		return;
	}
	const body = JSON.stringify({ usercode: user_name.value, userpw: user_pwd.value });
	// 调用user-login接口
	try {
		const res = await post(login, body) as { code: number, usercode: string, user_name: string, productid: string, sessionID: string };
		set('sessionid', res.sessionID);
		if (res.code === 1) {
			await set_user('user', res);
<<<<<<< HEAD
			direct_to("meeting-management.html");
=======
			direct_to("inventory-of-assets.html");
>>>>>>> 5882e85b58f6405982c891a61096b466a5f2234d
		}
	} catch (err) {
		let msg = '';
		try {
			msg = JSON.parse(err.message).msg;
		} catch (error) {
			msg = err.message;
		}
		await error(msg);
		throw Error(msg);
	}


}
